
fib xs n
    | xs == [] = fib [1,1] n
    | xs == [1] = fib [1,1] n
    | new < n = fib (xs ++ [new]) n
    | otherwise = xs
    where new = foldr (+) 0 (drop (length xs - 2) xs)

fibs = fib [] 1000000
evenValued = filter (\x -> x `mod` 2 == 0) fibs
overallSum = foldr (+) 0 evenValued
main = print $ overallSum
